
import java.nio.file.Paths;
import java.util.List;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.UserAuthNoneFactory;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.shell.InteractiveProcessShellFactory;
import org.apache.sshd.sftp.server.SftpSubsystemFactory;

public class SFTPd {
    public static void main(String[] args) throws Exception {
        var path = args.length == 0 ? "d:/z" : args[0];
        System.setProperty("user.home", path);
        var sshd = SshServer.setUpDefaultServer();
        sshd.setPort(2222);
        sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get(path, "key")));
        sshd.setUserAuthFactories(List.of(new UserAuthNoneFactory()));
        sshd.setSubsystemFactories(List.of(new SftpSubsystemFactory()));
        sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path, new String[0])));
        sshd.setShellFactory(InteractiveProcessShellFactory.INSTANCE);
        sshd.start();
        synchronized (sshd) {
            sshd.wait();
        }
    }
}